package com.xiaoshuidi.cloud.module.contract.enums.contract;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 业主合同状态的枚举类
 * private String contractStatus;
 *
 * @author 合房源码
 */
@Getter
@AllArgsConstructor
public enum ContractCompanyStatusEnum {
    ACTIVE("active", "已生效"),
    PENDING("pending","审批中"),
    RENEW("renew","已续租"),
    RENTING_OUT("renting_out", "已退租"),
    LOST_EFFECTIVENESS("lost_effectiveness","已失效"),
    ;
    //编码
    private final String code;
    //信息
    private final String msg;

    private static Map<String, ContractCompanyStatusEnum> enumMap = new HashMap<>();
    static {
        ContractCompanyStatusEnum[] values = ContractCompanyStatusEnum.values();
        for (ContractCompanyStatusEnum value : values) {
            enumMap.put(value.getCode(), value);
        }
    }
    public static ContractCompanyStatusEnum getEnum(String num){
        return enumMap.get(num);
    }

    public static ContractCompanyStatusEnum getContractStatusEnumByCode(String code) {
        ContractCompanyStatusEnum[] contractStatusEnums = values();
        for (ContractCompanyStatusEnum contractStatusEnum : contractStatusEnums) {
            if (contractStatusEnum.code.equals(code)) {
                return contractStatusEnum;
            }
        }
        return null;
    }

    public static String getName(String code) {
        for (ContractCompanyStatusEnum c : ContractCompanyStatusEnum.values()) {
            if (c.getCode().equals(code)) {
                return c.msg;
            }
        }
        return null;
    }

}
